import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

import FilePanel.Data;
import FilePanel.FilePanel;
import FilePanel.FilePanelImp;
import FilePanel.FilePanelModel;
import PlugIn.*;
import PlugIn.loader.PlugInFactory;


/**
 * Classe Main
 * Point d'entrée de l'application
 */
public class Main {

	
	public static void main(String[] args) {
		JFileChooser fileChooser = new JFileChooser(".");
		fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		int returnVal = fileChooser.showOpenDialog(null);
		File file = null;
		if (returnVal == JFileChooser.APPROVE_OPTION) {
            file = fileChooser.getSelectedFile();
        }
		String path = file.getPath();
		
		FilePanel panel = new FilePanelImp();
		Data data = panel.getData();
		Window main = new Window("LOG4430 Exo 1", panel);
		try {
			PlugInFactory.initialiserFactory(path, data);
		} catch (MalformedURLException e) {
			JOptionPane.showMessageDialog(null, "Le chemin d'accès au repertoire des Plugins est mal formée", "Erreur", JOptionPane.ERROR_MESSAGE);
			System.exit(1);
		}
		for(PlugIn pi : PlugInFactory.getFactory().getAllPlugIns()){
			main.addPlugin(pi);
		}
	}

}
